﻿CREATE VIEW dbo.v_FaxToDealer
AS
SELECT     dbo.t_Loan.ID LoanID, LOWER(t_Applicants.FirstName) AS FirstName, LOWER(t_Applicants.LastName) AS LastName, 
                      dbo.t_Dealer.Name AS DealerName, CONVERT(varchar(50), GETDATE(), 101) AS Date, CONVERT(varchar(5), GETDATE(), 108) AS Time, 
                      dbo.FormatPhone(dbo.t_Dealer.Phone) AS pHONE, dbo.t_Dealer.Fax, t_Applicants.SSN, t_LoanInfo.AdvancePercent, 
                      t_LoanInfo.LoanTerm AS ApprovedTerm, t_LoanInfo.APR, t_Applicants_1.FirstName AS FirstName1, 
                      t_Applicants_1.LastName AS LastName1, t_Applicants_1.SSN AS SSN1, t_LoanInfo.ProcessingFee, dbo.UserName() 
                      AS UserName, dbo.t_Dealer_SalesPersons.Name AS Contact, t_LoanInfo.PaymentAmount, t_LoanInfo.AmountFinanced, t_LoanInfo.DownPayment, 
                      CASE t_LoanInfo.Declined WHEN 1 THEN 'Declined' ELSE 'Approved' END AS DealCondition, t_LoanInfo.Declined
FROM         dbo.v_LoanInfo t_LoanInfo
INNER JOIN v_Borrower_0 t_Applicants ON t_Applicants.LoanID = t_LoanInfo.LoanID
INNER JOIN v_Borrower_1 t_Applicants_1 ON t_Applicants_1.LoanID = t_LoanInfo.LoanID
INNER JOIN
                      dbo.t_Loan ON t_LoanInfo.LoanID = dbo.t_Loan.ID INNER JOIN
                      dbo.t_Dealer_SalesPersons ON dbo.t_Loan.DealerSalesPersonID = dbo.t_Dealer_SalesPersons.ID INNER JOIN
                      dbo.t_Dealer ON dbo.t_Dealer_SalesPersons.DealerID = dbo.t_Dealer.ID 


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[37] 4[26] 2[19] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1[50] 2[25] 3) )"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1 [56] 4 [18] 2))"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "t_LoanSubject"
            Begin Extent = 
               Top = 145
               Left = 563
               Bottom = 365
               Right = 743
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_Dealer_SalesPersons"
            Begin Extent = 
               Top = 128
               Left = 822
               Bottom = 222
               Right = 973
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_Dealer"
            Begin Extent = 
               Top = 281
               Left = 951
               Bottom = 390
               Right = 1102
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_LoanInfo"
            Begin Extent = 
               Top = 253
               Left = 300
               Bottom = 569
               Right = 511
            End
            DisplayFlags = 280
            TopColumn = 16
         End
         Begin Table = "t_Applicants"
            Begin Extent = 
               Top = 74
               Left = 67
               Bottom = 452
               Right = 282
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_Applicants_1"
            Begin Extent = 
               Top = 13
               Left = 469
               Bottom = 122
               Right = 684
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      RowHeights = 220
      Begin ColumnWidths = 26', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_FaxToDealer';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'Width = 284
         Width = 975
         Width = 870
         Width = 1230
         Width = 1050
         Width = 990
         Width = 570
         Width = 1050
         Width = 1050
         Width = 960
         Width = 1440
         Width = 1215
         Width = 1080
         Width = 750
         Width = 960
         Width = 945
         Width = 960
         Width = 1440
         Width = 1440
         Width = 1440
         Width = 1440
         Width = 1440
         Width = 1440
         Width = 1440
         Width = 1440
         Width = 1440
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 5670
         Alias = 2055
         Table = 2040
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_FaxToDealer';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_FaxToDealer';

